﻿@{
 
    //very simple contact form add-on for razorC.net

    var customerName = Request["customerName"];
    var customerEmail = Request["customerEmail"];
    var customerPhone = Request["customerPhone"];
    var customerRequest = Request["customerRequest"];
    var isActive=true;
    var errMSG="";

    if (IsPost){


     Validation.RequireFields("customerName", "customerEmail", "customerPhone","customerRequest");
     Validation.Add("customerEmail",Validator.Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", "Please enter a correct email address format"));

     
        if (Validation.IsValid() ){

            var mailBody = "";
            foreach (var item in Request.Form)
            {
                mailBody += item.ToString() + " :" + Request[item.ToString()] + "<br/>";

            }
            


            try {        
               
               // Initialize WebMail helper
                WebMail.SmtpServer = App.SmtpServer;
                WebMail.SmtpPort = App.SmtpPort;
                WebMail.EnableSsl=App.EnableSsl;
                WebMail.UserName = App.UserName;
                WebMail.Password = App.Password;
                WebMail.From = App.From;
             

             // Send email        
             WebMail.Send(to: App.smtpTo, subject: "E-mail from website:" + App.siteName, body: mailBody);    
                errMSG="<div class=\"alert alert-success\">Thank You! Email sent</div>";
                isActive = false;
                
             }    catch (Exception ex ) {        
             errMSG= "<div class=\"alert alert-danger\"><b>The email was <em>not</em> sent.</b><br/>" + ex.Message.ToString() + "</div>";
  
            }
        }
    }
           

}



<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">@PageData[0].wTitle</h3>
        @*Html.Raw(PageData[0].wText)*@
    </div>
    <div class="panel-body">
        <form method="post" action="" role="form">

            @Html.Raw(errMSG)

            <div class="form-group">
                <label for="customerName">Your name:</label>
                <input type="text" name="customerName" value="@customerName" @Validation.For("customerName") class="form-control" id="customerName" placeholder="Enter name" /> @Html.ValidationMessage("customerName")
            </div>

            <div class="form-group">
                <label for="customerEmail">Your e-mail:</label>
                <input type="text" name="customerEmail" value="@customerEmail" @Validation.For("customerEmail") class="form-control" id="customerEmail" placeholder="Enter e-mail" /> @Html.ValidationMessage("customerEmail")
            </div>

            <div class="form-group">
                <label for="customerPhone">Your phone:</label>
                <input type="text" name="customerPhone" value="@customerPhone" @Validation.For("customerPhone") class="form-control" id="customerPhone" placeholder="Enter phone" /> @Html.ValidationMessage("customerPhone")
            </div>

            <div class="form-group">
                <label for="customerRequest">Message:</label>
                <textarea name="customerRequest" cols="45" rows="4" @Validation.For("customerRequest") class="form-control" id="customerRequest" placeholder="Message">@customerRequest</textarea> @Html.ValidationMessage("customerRequest")
            </div>

            <div class="form-group"><input type="submit" value="Submit" @(!isActive ? "disabled=disabled" : "") class="btn btn-primary" /></div>
        </form>
    </div>
</div>